﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AvatarHelper;
using Avatar.Model;

public partial class Management_JobsSet : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            using (var _adc = DBHelper.GetDataContext())
            {
                var _jobConfig = _adc.JobConfig.FirstOrDefault();
                if (_jobConfig != null)
                {
                    txt_Period.Text = _jobConfig.Period.ToString();
                    txt_Price.Text = _jobConfig.Price.ToString();
                }
            }
        }

    }
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        try
        {
            using (var _adc = DBHelper.GetDataContext())
            {
                var _jobConfig = _adc.JobConfig.FirstOrDefault();
                if (_jobConfig == null)
                {
                    _jobConfig = new JobConfig();
                    _jobConfig.Period = Convert.ToInt32(txt_Period.Text);
                    _jobConfig.Price = Convert.ToInt32(txt_Price.Text);
                    _adc.JobConfig.InsertOnSubmit(_jobConfig);
                }
                else
                {
                    _jobConfig.Period = Convert.ToInt32(txt_Period.Text);
                    _jobConfig.Price = Convert.ToInt32(txt_Price.Text);
                }
                _adc.SubmitChanges();
            }
        }
        catch (Exception _e)
        {
            lbl_Error.Text = "错误:" + _e.Message;
        }
    }
}
